#!/usr/bin/perl

require "./mailadmin-lib.pl";
&ReadParse();

my (%dft_uinfo, $msg_over_batnum);

unless (&qmail_dir_check())
{
    &redirect('maildir_edit.cgi');
}

$mydomain = `postconf mydomain`;
if($mydomain =~ /\S+\s+=\s+(\S+)/){
	$mydomain = $1;
}

$myhostname = `hostname`;
if($myhostname =~ /(\S+)/){
        $myhostname = $1;
}

$mailsize = `postconf message_size_limit`;
if($mailsize =~ /message_size_limit\s+=\s+(\S+)/){
        $mailsize = $1 / 1000 / 1024;
}

$mboxsize = `postconf mailbox_size_limit`;
if($mboxsize =~ /mailbox_size_limit\s+=\s+(\S+)/){
        $mboxsize = $1 / 1000 / 1024;
}


$msg_over_batnum = &text('msg_over_bataction_num', $config{'bataction_num'});

&header($text{'index_title'}, "", undef, 0, 1);

print "<form action=save_config_domain.cgi name=crtdform method=post onsubmit=\'return do_submit();\'>\n";

print "<table class=mode1 border=0 width=100%>\n";

print "<tr><td width=15%>$text{'cm_host'}</td><td>$myhostname</td></tr>\n";
print "<tr><td width=15%>$text{'cm_domain'}</td><td><input name=dname class=text value=\"$mydomain\"></td></tr>\n";

print "<tr><td>$text{'cm_max_mail'}</td><td><input name=mailsize class=text value=\"$mailsize\">MB</td></tr>\n";
print "<tr><td>$text{'cm_max_mbox'}</td><td><input name=mboxsize class=text value=\"$mboxsize\">MB</td></tr>\n";

print "</table>\n";

print "<p><input type=submit name=btn_create class=button1 value=\"$text{'btn_config'}\" onclick=\'return create_domain();\'>";

print "</form>\n";

print <<EOF;
<script>
function do_submit()
{
    document.forms[0].btn_create.disabled = true;
}

function create_domain()
{
    if (document.crtdform.dname.value == "")
    {
	alert("$text{'msg_dname_empty'}");
	return false;
    }

    if (document.crtdform.passwd.value != document.crtdform.con_passwd.value)
    {
	alert("$text{'msg_conpasswd_diff'}");
	return false;
    }
}

</script>
EOF


&footer("index.cgi", $text{"back_mailadmin"});
